package com.lagou.service.impl;

import com.lagou.base.StatusCode;
import com.lagou.dao.CourseContentDao;
import com.lagou.dao.impl.CourseContentDaoImpl;
import com.lagou.pojo.Course;
import com.lagou.pojo.Course_Lesson;
import com.lagou.pojo.Course_Section;
import com.lagou.service.CourseContentService;
import com.lagou.utils.DateUtils;

import java.util.List;


/**
 * 课程内容管理service层实现类
 */
public class CourseContentServiceImpl implements CourseContentService {

    CourseContentDao courseContentDao =new CourseContentDaoImpl();

    @Override
    public List<Course_Section> findSectionAndLessonByCourseId(int courseId) {
        List<Course_Section> sections = courseContentDao.findSectionAndLessonByCourseId(courseId);
        return sections;
    }

    @Override
    public Course findCourseByCourseId(int courseId) {
        Course course = courseContentDao.findCourseByCourseId(courseId);
        return course;
    }

    @Override
    public String saveSection(Course_Section course_section) {
        //补全章节信息
        course_section.setStatus(2);    //0:隐藏  1:待更新   2:已发布
        String dateFormart = DateUtils.getDateFormart();
        course_section.setCreate_time(dateFormart);
        course_section.setUpdate_time(dateFormart);

        int i = courseContentDao.saveSection(course_section);

        if (i>0){
            //保存成功
            String result = StatusCode.SUCCESS.toString();
            return result;
        }else {
            String result = StatusCode.FAIL.toString();
            return result;
        }

    }

    @Override
    public String updateSection(Course_Section course_section) {
        //补全信息
        course_section.setUpdate_time(DateUtils.getDateFormart());

        int row = courseContentDao.updateSection(course_section);
        if (row>0){
            //修改成功
            String result = StatusCode.SUCCESS.toString();
            return result;
        }else {
            String result = StatusCode.FAIL.toString();
            return result;
        }

    }

    @Override
    public String updateSectionStatus(int id, int status) {
        int row = courseContentDao.updateSectionStatus(id, status);
        if (row>0){
            //修改状态成功
            String result = StatusCode.SUCCESS.toString();
            return result;
        }else {
            String result = StatusCode.FAIL.toString();
            return result;
        }
    }

    @Override
    public String saveLesson(Course_Lesson course_lesson) {
        //1.补全课时信息
        String dateFormart = DateUtils.getDateFormart();
        course_lesson.setUpdate_time(dateFormart);
        course_lesson.setCreate_time(dateFormart);
        course_lesson.setStatus(2);
        int row = courseContentDao.saveLesson(course_lesson);
        if (row>0){
            //保存成功
            String result = StatusCode.SUCCESS.toString();
            return result;
        }else {
            String result = StatusCode.FAIL.toString();
            return result;
        }
    }

    @Override
    public String updateLesson(Course_Lesson course_lesson) {
        course_lesson.setUpdate_time(DateUtils.getDateFormart());
        int row = courseContentDao.updateLesson(course_lesson);
        if (row>0){
            //修改状态成功
            String result = StatusCode.SUCCESS.toString();
            return result;
        }else {
            String result = StatusCode.FAIL.toString();
            return result;
        }
    }
}
